package com.ruoyi.personnel.oa.meeting.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.personnel.oa.meeting.domain.MeetingCond;
import com.ruoyi.personnel.oa.meeting.domain.MeetingDomain;
import com.ruoyi.personnel.oa.meeting.domain.MeetingDto;
import com.ruoyi.personnel.oa.meeting.service.IMeetingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 视图层
 * 会议
 */
@RestController
@RequestMapping("/oa/meeting")
@Api(value = "会议模块", tags = "会议接口")
public class MeetingController extends BaseController {
    @Autowired
    private IMeetingService meetingService;

    /**
     * 根据搜索条件所有会议记录
     * @param cond 搜索条件
     * @return
     */
    @ApiOperation(value = "获取会议列表",notes = "查询所有会议信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody MeetingCond cond) {
        startPage();
        List<MeetingDto> meetingDtos = meetingService.selectMeetingList(cond);
        return getDataTable(meetingDtos);
    }

    /**
     * 导出会议记录
     * @param cond
     * @return
     */
    @PostMapping("/export")
    @ApiOperation("导出会议")
    public AjaxResult export(@RequestBody MeetingCond cond)
    {
        List<MeetingDto> meetingDtos = meetingService.selectMeetingList(cond);
        ExcelUtil<MeetingDto> util = new ExcelUtil<>(MeetingDto.class);
        return util.exportExcel(meetingDtos, "会议");
    }

    /**
     * 新增会议
     * @param meeting
     * @return
     */
    @ApiOperation(value = "新增会议", notes = "新增会议")
    @ApiImplicitParam(name = "meeting", value = "新增会议", dataType = "MeetingDomain")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody MeetingDomain meeting) {
        return toAjax(meetingService.insertMeeting(meeting));
    }

    /**
     * 修改部门日程记录
     * @param meeting
     * @return
     */
    @ApiOperation(value = "修改会议", notes = "修改会议")
    @ApiImplicitParam(name = "meeting", value = "修改会议", dataType = "MeetingDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody MeetingDomain meeting) {
        return toAjax(meetingService.updateMeeting(meeting));
    }

    /**
     * 删除会议
     * 仅修改删除标志
     * @param meeting
     * @return
     */
    @ApiOperation(value = "删除会议", notes = "删除会议记录,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody MeetingDomain meeting) {
        return toAjax(meetingService.updateMeetingDeleteFlag(meeting));
    }
}
